	foodList();//根据支付状态获取订单列表
	

	//根据支付状态获取订单列表
	function foodList(){
		
		var Request = new Object();
    	Request = GetRequest();
    	var status = Request['status'];

    	if(status == 1){
    		$(".order-sw div").eq(1).addClass("order-current").siblings().removeClass("order-current");
    		findFoodOrderList(0,this,0);//获取待付款订单列表
    	}else if(status == 2){
    		$(".order-sw div").eq(2).addClass("order-current").siblings().removeClass("order-current");
    		findFoodOrderList(2,this,0);//获取待取餐订单列表
    	}else{
    		findFoodOrderList(-1,this,0);//获取全部订单列表

    	}
	}

	//获取订单列表
	function findFoodOrderList(status,that,page,isRefresh){
		
		$(that).addClass("order-current").siblings().removeClass("order-current");

		// var page = 0;
		// var size = 5;
		var size = 20;
		if(page==0){

		}else{
			page = Math.ceil($(".order-ul li").length/size);
		}
		
		var sort = "created_date,desc";
		var status = status;

		var obj = JSON.stringify({
			"status": status
		});
		
		httpHelperpost(_API_FOOD_ORDER_LIST+"?page="+page+"&size="+size+"&sort="+sort, obj, function(isSuccess, data) {
	        if (isSuccess == true) {
	            var response = data.responseText;
	            var value = JSON.parse(response);
	    			
	   			console.log(response);
	   			var orderHtml = "";
	   			var totalPrice = 0;
	   			var id = 0;
	   			var statusTar = 0;

	   			for(var i=0;i<value.data.length;i++){
	   				var orderTime = value.data[i].orderTime.substring(0,16);
	   				totalPrice = value.data[i].factPrice;
	   				id = value.data[i].id;
	   				statusTar = value.data[i].status;

	   				orderHtml += "<li class='order-li'>"
	   							+"<div class='order-top'>"
	   							+"<div class='order-top-title'><img src="+value.data[i].restaurantIcon+"><span>"+value.data[i].restaurantName+"</span></div>";
	   				if(statusTar==1){
	   					orderHtml+="<div class='order-top-state'>待发货</div>";
	   				}else if(statusTar==2){
	   					orderHtml+="<div class='order-top-state'>待取餐</div>";
	   				}

	   				orderHtml+="</div>"
	   							+"<div class='order-bar' onclick=submitOrderDetail('"+id+"');>"
	   							+"<div class='order-bar-img'><img src="+value.data[i].foodList[0].picture+"></div>"
	   							+"<div class='order-bar-text'>"
	   							+"<div class='order-bar-name'>"+value.data[i].foodList[0].name+"</div>"
	   							+"<div class='order-bar-time'>下单时间：<span>"+orderTime+"</span></div>"
	   							+"<div class='order-bar-price'>总价：<span class='totalMoney'>￥"+totalPrice+"</span></div>"
	   							+"</div>"
	   							+"</div>";
	   					if(statusTar==0){
	   						orderHtml+="<div class='order-btn'><button class='order-btn-comment' onclick=payMoney('"+id+"',1);>付款</button></div>";
	   					}else if(statusTar==1){
	   						orderHtml+="<div class='order-btn'><button>待发货</button></div>";
	   					}else if(statusTar==2){
	   						orderHtml+="<div class='order-btn'><button class='order-btn-comment' onclick=confirmGoods('"+id+"');>确认</button><button class='order-btn-comment' onclick=window.location.href='orderDetail.html?id="+id+"&status="+status+"'>查看详情</button></div>";
	   					}else if(statusTar==3){
	   						orderHtml+="<div class='order-btn'><button class='order-btn-comment' onclick=commentBtn();>评价</button><button class='order-btn-comment' onclick=applyAfterSaleLogic('"+id+"');>申请售后</button></div>";
	   					}else{
	   						if(value.data[i].afterSaleState==0){
	   							orderHtml+="<div class='order-btn'>售后状态:待审核</div>";
	   						}else if(value.data[i].afterSaleState==1){
	   							orderHtml+="<div class='order-btn'>售后状态:审核通过</div>";
	   						}else if(value.data[i].afterSaleState==2){
	   							orderHtml+="<div class='order-btn'>售后状态:审核不通过</div>";
	   						}else if(value.data[i].afterSaleState==3){
	   							orderHtml+="<div class='order-btn'>售后状态:已处理</div>";
	   						}
	   					}
	   							
	   				orderHtml+="</li>";

	   			}
	   			
	   			
	
	            if(value.code == 0){
	             	console.log("查询成功");
	             	if(isRefresh==1){
	             		$(".order-ul").append(orderHtml);
	             	}else{
	             		$(".order-ul").html(orderHtml);
	             	}
	             	if(value.data==""){

	             	}else{
	             		dropRefresh();
	             	}
	             	
	            }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
	            	alert(value.message);
	             	console.log("查询失败");
	            }
	        }else {}
	    });
	}

	//评价按钮
	function commentBtn(){
		alert("该功能正在开发中");
	}

	//跳转到订单详情页面
	function submitOrderDetail(id){
		window.location.href="submitOrderDetail.html?id="+id;
	}

	//确认收货(状态由待取餐变成待评价)
    function confirmGoods(orderId){
    	
    	var userId = "1";
    	var obj = JSON.stringify({
            "userId": userId,
            "id": orderId,
        });
        httpHelperpost(_API_CONFIEMRM_GOODS, obj, function(isSuccess, data) {
        	if (isSuccess == true) {
        	    var response = data.responseText;
        	    var value = JSON.parse(response);
    				
   				console.log(response);
   				
        	    if(value.code == 0){
        	     	console.log("确认成功");
        	     	findFoodOrderList(3,this,0);
        	     	$(".order-sw div").eq(3).addClass("order-current").siblings().removeClass("order-current");
        	    }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
        	    	alert(value.message);
        	     	console.log("确认失败");
        	    }
        	}else {}
    	});
    }

    //付款逻辑(状态由付款变成待发货)
    function payMoney(id,userId){
    	$(".zhezhao").css("display","block");
    	$(".payLight").css("display","block");
    	$(".payLight .payLight_sure").click(function(){
            if($(".payLight_panel input").val()==""){
                alert("请输入密码");
            }else if($(".payLight_panel input").val()!="123456"){
                alert("密码错误，支付失败");
            }else{
                foodOrderSyncNotify(id,userId);
            }
            
        });
    }

    //支付同步(付款)
    function foodOrderSyncNotify(id,userId){
	    var obj = JSON.stringify({
	        "id":id,
	        "userId":userId,
	    });
	    httpHelperpost(_API_FOOD_ORDER_SYNC_NOTIFY, obj, function(isSuccess, data) {
	        if (isSuccess == true) {
	            var response = data.responseText;
	            var value = JSON.parse(response);
	                
	            console.log(response);
	            
	            var status = 1;
	            if(value.code == 0){
	                console.log("支付成功");
	                alert("支付成功");
	                status = 1;
	                window.location.href = "./order.html?status="+status;
	            }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
	                console.log("支付失败");
	                alert("支付失败"+value.code);
	                // window.location.href = "./foodAuditSF.html?status="+status;
	            }
	        }else {}
	    });
	}

	//申请售后按钮逻辑
	function applyAfterSaleLogic(id){
		$(".saleLight").css("display","block");
		$(".zhezhao").css("display","block");

		$(".saleLight .payLightBtn").html("<button onclick=applyAfterSale('"+id+"'); class='payLight_sure'>确定</button>")
		
	}
	//申请售后按钮功能
	function applyAfterSale(id){

		var afterSaleReason = $(".saleLight input").val();
		var obj = JSON.stringify({
	        "id":id,
	        "afterSaleReason":afterSaleReason
	    });
	    if(afterSaleReason==""||afterSaleReason==null||afterSaleReason==undefined){
	    	alert("请输入申请原因");
	    }else{
	    	httpHelperpost("/api/afterSales/applyAfterSale", obj, function(isSuccess, data) {
	        	if (isSuccess == true) {
	        	    var response = data.responseText;
	        	    var value = JSON.parse(response);
	        	        
	        	    console.log(response);
	        	    
	        	    var status = 1;
	        	    if(value.code == 0){
	        	       	$(".saleLight").css("display","none");
						$(".zhezhao").css("display","none");
						$(".order-sw >div:nth-child(5)").click();
						alert(value.message);
	        	    }else if(value.code==401){
	        	    	alert(value.message);
	        	    	window.location.href='./index.html';
	        	    }else{
	        	    	alert(value.message);
	        	        console.log("申请失败");
	        	    }
	        	}else {}
	    	});
	    }
	}

    //下拉刷新
    function dropRefresh(){
    	var index = 0;
    	var lastNumber = 0;
    	$(window).scroll(function() {
			var scrollTop = $(document).scrollTop();//滚动条距离页面顶部距离
			var offsetHeight = $(document).height();//当前页面高度(包括滚动页面)
			var clientHeight = $(this).height();//当前页面高度(不包括滚动页面)
			var bottomHeight = scrollTop-(offsetHeight-clientHeight);
			if(bottomHeight>=-1&&bottomHeight<1){
				// lastNumber = $(".order-li").length+5;
				index = $(".order-sw .order-current").index();
				if(index==0){
					findFoodOrderList(-1,this,null,1);
				}else if(index==1){
					findFoodOrderList(0,this,null,1);
				}else if(index==2){
					findFoodOrderList(2,this,null,1);
				}else if(index==3){
					findFoodOrderList(3,this,null,1);
				}else if(index==4){
					findFoodOrderList(4,this,null,1);
				}else{}
				
				$(window).unbind("scroll");		
			}
		});
    }

	//获取url中"?"符后的字串
	function GetRequest() {
	    var url = location.search; //获取url中"?"符后的字串   
	    
	    var theRequest = new Object();
	    if (url.indexOf("?") != -1) {
	      var str = url.substr(1);
	      
	      strs = str.split("&");
	      
	      for (var i = 0; i < strs.length; i++) {
	        
	        theRequest[strs[i].split("=")[0]] = strs[i]
	            .split("=")[1];
	      }
	    }
	    return theRequest;
	}

	function zhezhao(){
	    $(".zhezhao").css("display","none");
	    // $(".selectLight").css("display","none");
	    $(".light").css("display","none");
	}